<?php


namespace App\Helpers;


use App\Models\ActionLog;
use App\Models\Mch\RegisterCode;
use Carbon\Carbon;

trait BooksTrait
{
    // 书籍是否开锁
   protected function isLock($item,$list,$userId){
       if($item->is_lock==1){
            return 1;
       }
       if($list){
           if(count($list)>0){
               if(in_array($item->id,$list)){
                   $isVoid = RegisterCode::query()
                       ->select('finish_time')
                       ->where('use_id',$userId)
                       ->where('register_type',2)
                       ->where('class_id',$item->id)
                       ->where('enable',1)
                       ->where('finish_time','>',now())->first();
                   if($isVoid){
                       return 1;
                   }
               }
           }
       }
       return 2;
   }
}
